package iD220711010131;

import java.util.LinkedList;
import java.util.Scanner;

public class HuangJiaLe02 {
    static Scanner sc = new Scanner(System.in);
    static LinkedList<String> list = new LinkedList<String>();
    public static void main(String[] args) {
        list.add("晴天");
        list.add("南方姑娘");
        list.add("Julie");
        list.add("不得不爱");
        w:while(true) {
            System.out.println("选歌系统功能如下：");
            System.out.println("1、添加歌曲");
            System.out.println("2、歌单查看");
            System.out.println("3、歌曲置顶");
            System.out.println("4、歌曲前移一位");
            System.out.println("5、退出系统");
            System.out.println("请选择对应编号进行操作：");
            int choice = sc.nextInt();
            switch(choice) {
                case 1:
                    add();
                    show();
                    break;
                case 2:
                    show();
                    break;
                case 3:
                    top();
                    show();
                    break;
                case 4:
                    advance();
                    show();
                    break;
                case 5:
                    break w;
            }
        }
    }

    private static void advance() {
        // TODO Auto-generated method stub
        System.out.println("是否前移歌曲？输入yes/no");
        String choice = sc.next();
        System.out.println("输入需要前移一位的歌曲名称：");
        String name = sc.next();
        int position = list.indexOf(name);
        if(position == 0) {
            System.out.println("该歌曲已位于首位，无法前移！！！");
        }else if(position < 0) {
            System.out.println("该歌曲不存在您的歌单中，无法前移！！！");
        }else if( position < list.size() && position > 0) {
            list.remove(position);
            list.add(position-1, name);
            System.out.println("前移成功");
        }
    }

    private static void top() {
        // TODO Auto-generated method stub
        System.out.println("是否置顶歌曲？输入yes/no");
        String choice = sc.next();
        if(choice.equals("yes")) {
            System.out.println("请输入需要置顶的歌曲名称：");
            String name = sc.next();
            int position = list.indexOf(name);
            if(position == 0) {
                System.out.println("该歌曲已经在顶部");
            }else if(position > 0 && position < list.size()) {
                list.remove(name);
                list.addFirst(name);
                System.out.println("置顶成功！！！");
            }else if(position < 0) {
                System.out.println("该歌曲不存在您的歌单，无法置顶");
            }
        }else if(choice.equals("no")) {
            
        }else {
            System.out.println("输入有误！！！");
            top();
        }
    }

    private static void show() {
        // TODO Auto-generated method stub
        for(String name : list) {
            System.out.println(list.indexOf(name)+1 + "、" + name);
        }
    }

    private static void add() {
        // TODO Auto-generated method stub
        System.out.println("是否添加歌曲？输入yes/no");
        String choice = sc.next();
        if(choice.equals("yes")) {
            System.out.println("请输入需要添加的歌曲名称：");
            String name = sc.next();
            list.add(name);
        }else if(choice.equals("no")) {
            return;
        }else {
            System.out.println("输入有误！！！");
            add();
        }
        
    }
}
